package com.fau.wmbj.server.flowable.cmd;

import cn.hutool.core.collection.CollUtil;
import com.fau.wmbj.server.utils.SpringUtils;
import org.apache.commons.lang3.StringUtils;
import org.flowable.common.engine.impl.interceptor.Command;
import org.flowable.common.engine.impl.interceptor.CommandContext;
import org.flowable.engine.impl.persistence.entity.AttachmentEntity;
import org.flowable.engine.impl.persistence.entity.AttachmentEntityManager;
import org.flowable.engine.impl.util.CommandContextUtil;

import java.util.Date;
import java.util.List;

/**
 * 附件上传
 */
public class AttachmentCmd implements Command<Boolean> {

    private final String fileId;

    private final String taskId;

    private final String processInstanceId;

    public AttachmentCmd(String fileId, String taskId, String processInstanceId) {
        this.fileId = fileId;
        this.taskId = taskId;
        this.processInstanceId = processInstanceId;
    }

    @Override
    public Boolean execute(CommandContext commandContext) {
        try {
            if (StringUtils.isNotBlank(fileId)) {
                // List<OssFile> ossList = SpringUtils.getBean(OssService.class).selectByIds(fileId);
                // if (CollUtil.isNotEmpty(ossList)) {
                //     for (OssFile oss : ossList) {
                //         AttachmentEntityManager attachmentEntityManager = CommandContextUtil.getAttachmentEntityManager();
                //         AttachmentEntity attachmentEntity = attachmentEntityManager.create();
                //         attachmentEntity.setRevision(1);
                //         attachmentEntity.setUserId("");
                //         attachmentEntity.setName("");
                //         attachmentEntity.setDescription("");
                //         attachmentEntity.setType("");
                //         attachmentEntity.setTaskId(taskId);
                //         attachmentEntity.setProcessInstanceId(processInstanceId);
                //         attachmentEntity.setContentId("");
                //         attachmentEntity.setTime(new Date());
                //         attachmentEntityManager.insert(attachmentEntity);
                //     }
                // }
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return true;
    }
}
